import processing.video.*;
import controlP5.*;

Capture cam;
boolean isOk;
ControlP5 cp5;
color c;
static final int CAMERA_WIDTH=1280;
static final int CAMERA_HEIGHT=720;

void setup(){
  size(1200, 700);
  cam = new Capture(this, CAMERA_WIDTH, CAMERA_HEIGHT, 30);
  cam.start();
  
  cp5 = new ControlP5(this);
}

void draw() {
  int i=0;
  if(cam.available()) {
    cam.read();
  }
  image(cam, 0, 0);
  if (isOk){
    PImage img=createImage(CAMERA_WIDTH,CAMERA_HEIGHT, RGB);
    img.loadPixels();
    //rempli le tableau pixel[]
      c = pixels[i];
      for (i=0;i<(CAMERA_WIDTH + CAMERA_HEIGHT); i++){
        if (hue(pixels[i])<hue(c)+500 && hue(pixels[i])>hue(c)-500){
          pixels[i]=color(100,50,500);
       }
     }
    //println(c);
    updatePixels(); 
   }
}

void mousePressed(){
  loadPixels();
  c = img.pixels[mouseX+mouseY*CAMERA_WIDTH];
  isOk = true;
  println(c);
  }
